<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*,cn.jingsheng.backup.bean.*,cn.jingsheng.backup.util.*"
    pageEncoding="UTF-8"%>
    <%
    //分页信息
    PagedListInfo info = (PagedListInfo) request.getSession().getAttribute("PagedListInfo");
	if(info==null){info = new PagedListInfo();}
	//搜索关键字
	String searchKey = (String)session.getAttribute("searchKey");
	if(searchKey==null){
		searchKey="";
	}
	UserLogin userLogin = (UserLogin) session.getAttribute("userLogin");
	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>竞盛公司业务文档电子报备系统</title>
<style type="text/css">
#thread_header li, #thread_footer li {
    float: left;
}
.pagination {
    font: 12px/22px Verdana;
}
.pagination {
    margin-left: 8px;
}
ul, li {
    margin: 0;
    padding: 0;
}
</style>
<script type="text/javascript">
function showAll(){
	document.SearchForm.searchKey.value="";
	document.SearchForm.submit();
}
function changeCountOfPage(){
	window.location.href="BackupServlet?cmd=show&startNum=1&countOfPage="+document.getElementById("countOfPage").value;
}

function searchTextTiptop(){
	var searchKey = document.getElementById("searchKey");
	if(searchKey.value=="请在这里输入关键字"){
		searchKey.value="";
	}else if(searchKey.value==""){
		searchKey.value="请在这里输入关键字";
	}
}
function showTable(id){
	var thisDiv = document.getElementById(id);
	
	if(thisDiv.style.display=="block"){
		thisDiv.style.display="none";
	}else{
		thisDiv.style.display="block";
	}
}
function hiddenTable(id){
	var thisDiv = document.getElementById(id);
	thisDiv.style.display="none";
}
function setDialog(width,height){
	return "dialogWidth="+width+"px;dialogHeight="+height+"px;";
}
</script>
</head>
<body>
<!-- 登录 -->
<div style="top: 10px;float: right;font-size: 12px;">
<%if(CommonUtil.isNotLogin(session)) {%>
<a href="javascript:window.showModalDialog('login.html',null,setDialog(600,300));window.location.href='BackupServlet';">登录</a>
<%}else{ %>
<font size="2">您好,尊敬的</font><font size="2" color="RED">[<%=userLogin.getUserName() %>]</font>
<%if(CommonUtil.isAdministrator(session)){ %>
<a href="BackupServlet?cmd=listUser" target="_blank">用户管理</a>
<%} %>
<a href="#" onclick="javascript:window.showModalDialog('change_password.jsp',null,setDialog(600,300));">修改密码</a>
<a href="BackupServlet?cmd=logout">注销</a>
<%}%>
</div>

<div style="float: center;margin-left: 10%;margin-right: 10%;height:auto;">
	<p align="center" style="font-size: 24px;">竞盛公司业务文档电子报备系统</p>
	<table width="100%" border=0>
		<tr>
			<td align="left">
			<form action="BackupServlet?cmd=show" method="post" name="SearchForm">
				<input size="25" name="searchKey" id="searchKey" value="<%=StringUtil.isEmpty(searchKey)?"请在这里输入关键字":searchKey%>" onfocus="searchTextTiptop();" onblur="searchTextTiptop();"/>
				<input type="submit" value="搜索"/>
				<input type="button" value="显示全部"  onclick="showAll();" <%=searchKey!=null&&searchKey.length()!=0?"":"disabled='disabled'" %>/>
			</form>
			</td>
			<td align="right">
				<input type="button" <%=userLogin!=null&&userLogin.canUpload()?"":"disabled='disabled'" %>value="上传报备文件" onclick="window.showModalDialog('upload_file.jsp',null,setDialog(800,600));window.location.href='BackupServlet';"/>
			</td>
		</tr>
	</table>
<!-- 	<div style="float: left;position:relative;"> -->
		
<!-- 	</div> -->
<!-- 	<div style="float: right;position:relative;"> -->
<!-- 		<input type="button" value="上传报备文件" onclick="window.showModalDialog('upload_file.jsp');window.location.href='BackupServlet';"/> -->
<!-- 	</div> -->
	<div style="position:absolute;top:120px;width:80%;">
	<table border="1px" width="100%">
		<tr>
			<td>&nbsp;</td>
			<td>报备文件名<a href="BackupServlet?cmd=show&sort=alias_file_name&ad=<%=info.getAscOrDesc("alias_file_name")%>"><img border="0" src="images/<%=info.getAscOrDesc("alias_file_name")%>.png"></a></td>
			<td>所属公司<a href="BackupServlet?cmd=show&sort=company&ad=<%=info.getAscOrDesc("company")%>"><img border="0" src="images/<%=info.getAscOrDesc("company")%>.png"></a></td>
			<td>文档类型</td>
			<td>报备时间<a href="BackupServlet?cmd=show&sort=create_time&ad=<%=info.getAscOrDesc("create_time")%>"><img border="0" src="images/<%=info.getAscOrDesc("create_time")%>.png"></a></td>
			<td>报备人<a href="BackupServlet?cmd=show&sort=create_user&ad=<%=info.getAscOrDesc("create_user")%>"><img border="0" src="images/<%=info.getAscOrDesc("create_user")%>.png"></a></td>
			<td>关键字<a href="BackupServlet?cmd=show&sort=search_key&ad=<%=info.getAscOrDesc("search_key")%>"><img border="0" src="images/<%=info.getAscOrDesc("search_key")%>.png"></a></td>
			<!-- 登录状态显示操作 -->
			<%if(CommonUtil.isLogin(session)){%>
			<td>&nbsp;</td>
			<%} %>
		</tr>
		<%	List<BackupFile> listBackup = (List<BackupFile>) request.getAttribute("listBackup");
			for (int i = 0; listBackup != null && i != listBackup.size(); i++) {
				BackupFile back = listBackup.get(i);%>
		<tr>
			<td><%=i + 1%>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(back.getAliasFileName())%>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(back.getCompany()) %>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(back.getFileType()) %>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(DateTimeUtil.format(back.getCreateTime(),"yyyy-MM-dd")) %>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(back.getCreateUser()) %>&nbsp;</td>
			<td><%=StringUtil.trimToEmpty(back.getSearchKey()) %>&nbsp;</td>
			<!-- 登录状态显示操作 -->
			<%if(CommonUtil.isLogin(session)){%>
			<td style="font-size: 12px;">&nbsp;
				<%
				if(userLogin.canView()){
				%>
				<a href="BackupServlet?cmd=viewinbrowse&id=<%=StringUtil.trimToEmpty(back.getId()) %>" target="_blank">查看</a>&nbsp;
				<%}if(userLogin.canDownload()){  %>
				<a href="BackupServlet?cmd=download&id=<%=StringUtil.trimToEmpty(back.getId()) %>" >下载</a>&nbsp;
				<%}if(userLogin.canDelete()){  %>
				<a href="BackupServlet?cmd=delete&id=<%=StringUtil.trimToEmpty(back.getId()) %>" >删除</a>&nbsp;
				<!-- 当前用户文档且为可编辑文档 -->
				<%}if(back.isEditable()&&userLogin.getUserName().equals(back.getCreateUser())){ %>
				<a href="BackupServlet?cmd=toupdate&id=<%=StringUtil.trimToEmpty(back.getId()) %>" >修改</a>&nbsp;
				<!-- 当为管理员时 可修改文档可编辑状态 -->
				<%}if(CommonUtil.isAdministrator(session)){%>
				<a href="BackupServlet?cmd=edit&id=<%=StringUtil.trimToEmpty(back.getId()) %>&editable=<%=!back.isEditable() %>" >置为<%=back.isEditable()?"不":"" %>可编辑</a>&nbsp;
				<%} %>
			<%} %>
		</tr>
		<%
			}
		%>
	</table>
	<br/>
	<ul>
	<li class="pagination">
	<%if(info.getStartNum()>1){ %>
	<a href="BackupServlet?cmd=show&startNum=1">首页</a>
	<%}if(info.currentPage()!=0) {%>
	<a href="BackupServlet?cmd=show&startNum=<%=info.backwordPage()*info.getCountOfPage()+1%>">上一页</a>
	<%}for(int i=0;i!=info.lastPage();i++){ if(i==info.currentPage()){%>
		<%=i + 1 %>
	<%}else{ %>
		<a href="BackupServlet?cmd=show&startNum=<%=i*info.getCountOfPage()+1 %>"><%=i+1 %></a>
	<%}} %>
	<%if(info.forwordPage()<info.lastPage()) {%>
	<a href="BackupServlet?cmd=show&startNum=<%=info.forwordPage()*info.getCountOfPage()+1%>">下一页</a>
	<%}if(info.currentPage()<info.lastPage()-1){ %>
	<a href="BackupServlet?cmd=show&startNum=<%=(info.lastPage()-1)*info.getCountOfPage()+1%>">尾页</a>
	<%} %>
	<select id="countOfPage" onchange="changeCountOfPage();">
		<option value="5" <%=info.getCountOfPage()==5?"selected='selected'":"" %>>每页 5 行</option>
		<option value="10" <%=info.getCountOfPage()==10?"selected='selected'":"" %>>每页 10 行</option>
		<option value="15" <%=info.getCountOfPage()==15?"selected='selected'":"" %>>每页 15 行</option>
		<option value="20" <%=info.getCountOfPage()==20?"selected='selected'":"" %>>每页 20 行</option>
		<option value="25" <%=info.getCountOfPage()==25?"selected='selected'":"" %>>每页 25 行</option>
	</select>
	</li>
	</ul>
	</div>
</div>
</body>
</html>